﻿ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// 控制视角的脚本
/// </summary>
public class ViewA : MonoBehaviour
{
    [Header("俯视摄像机")]
    public GameObject topCamera;

    [Header("立体摄像机")]
    public GameObject _3DCamera;
    [Header("导航箭头")]
    public GameObject im;

    [Header("按钮文本")]
    public Text text;

    [Header("切换到顶视图要打开的（3D关闭）")]
    public GameObject[] topGameObjects;

    [Header("切换到3D视图要打开的（顶关闭）")]
    public GameObject[] _3dGameObjects;

    bool is3D;

    // Start is called before the first frame update
    void Start()
    {
        if (_3DCamera&& topCamera)
        {
            is3D = false;
            Set3D(is3D);
        }
    }

    public void SwitchView()
    {
        if (is3D)
        {
            is3D = false;
        }
        else
        {
            is3D = true;
        }

        Set3D(is3D);
    }

    private void Set3D(bool is3D)
    {
        if (is3D)
        {
            _3DCamera.SetActive(true);
            topCamera.tag = "Camera";
            _3DCamera.tag = "MainCamera";
            topCamera.SetActive(false);
            text.text = "切换到平面视图";
            im.SetActive(true);

            foreach(GameObject gameObject in topGameObjects)
            {
                if(gameObject)
                    gameObject.SetActive(false);
            }

            foreach (GameObject gameObject in _3dGameObjects)
            {
                if (gameObject)
                    gameObject.SetActive(true);
            }

        }
        else
        {
            _3DCamera.SetActive(false);
            _3DCamera.tag = "Camera";
            topCamera.tag = "MainCamera";
            topCamera.SetActive(true);
            text.text = "切换到立体视图";
            im.SetActive(false);

            foreach (GameObject gameObject in topGameObjects)
            {
                if (gameObject)
                    gameObject.SetActive(true);
            }

            foreach (GameObject gameObject in _3dGameObjects)
            {
                if (gameObject)
                    gameObject.SetActive(false);
            }
        }
    }
}
